<#import '/ftlLibrary/properteisVariable.ftl' as pv/>
<style>
    .bootbox-close-button {
        width: 19px;
        height: 19px;
        border: none;
        cursor: pointer;
        -webkit-appearance: none;
        float: right;
        top: 4px;
        left: -5px;
        position: relative;
        background: #E9F5FF url("assets/img/nav-img/icon_close.png") no-repeat 0 0;
    }

    .bootbox .modal-dialog {
        width: 50% !important;
    }

    .modal-content {
        width: 100%;
    }

    input, select, .form-control {
        height: 30px;
    }

    .myDialogDetail label {
        margin-bottom: 0px !important;
    }

    th, td {
        height: 34.29px !important;
    }

    .detailDialogStyle {
        line-height: 30px;
        margin-bottom: 15px;
    }

    .myDialogDetail1 .modal-body {
        padding-bottom: 0px !important;
        border-bottom-right-radius: 5px !important;
        border-bottom-left-radius: 5px !important;
    }

    #tssMemberAddRecordDiv label{
        margin-bottom: 0px!important;
        line-height: 30px;
    }

</style>
<div class="col-lg-12 col-sm-12 col-xs-12 tssMemberAddRecordDiv2 tssMemberAddRecordDiv" id="tssMemberAddRecordDiv">
    <form class="editForm" action="${saveUrl}" method="post" responseType="JSON" role="form"
          id="subtractEditForm_${serializeNum}"
          data-bv-submitButtons="#editFormSubmitBtn_${serializeNum}"
          data-bv-message="This value is not valid"
          data-bv-feedbackicons-valid="glyphicon glyphicon-ok"
          data-bv-feedbackicons-invalid="glyphicon glyphicon-remove"
          data-bv-feedbackicons-validating="glyphicon glyphicon-refresh">
        <input type="hidden" name="id" value="${editEntity.id}">
        <input type="hidden" name="memberPackageId" value="${memberPackageId}" class="memberPackageId">
        <input type="hidden" name="addSubtractType" value="2">
        <#if (true && editModel=='add')||(true && editModel=='edit')>
            <div class="col-xm-12 col-sm-6 col-lg-12 margin-top-30">
                <div class="form-group">
                    <label class="col-sm-2 col-sm-offset-1 control-label no-padding-right"><span style="color: red">*</span>课时类型：</label>
                    <div class="col-sm-3">
                        <select class="form-control"  name="classHourType" style="border: 1px solid #c6d5d8;border-radius: 4px !important;" id="classHourType" value="${editEntity.classHourType}">
                            <option value="">请选择</option>
                            <@dictionary groupCode="classHourType";dics>
                            <#list dics as dic>
                                <option value="${dic.code}">${dic.value}</option>
                            </#list>
                        </@dictionary>
                        </select>
                    </div>

                </div>
            </div>
        </#if>
        <#if (true && editModel=='add')||(true && editModel=='edit')>
            <div class="col-xm-12 col-sm-6 col-lg-12">
                <div class="form-group">
                    <label  class="col-sm-2 col-sm-offset-1 control-label no-padding-right"><span style="color: red">*</span>减课时数：</label>
                    <div class="col-sm-3">
                        <input data-bv-integer-message="请输入数字" style="border: 1px solid #c6d5d8;border-radius: 4px !important;" onkeyup="verificationNumber(this)"
                               data-bv-message="请输入减课时数" data-bv-integer="true" data-max="" id="classHour"
                               name="classHour" alt="减课时数" id="classHour" placeholder="减课时数" type="text"
                               title="加课时数" class="form-control" value="${editEntity.classHour}"/>
                        <span class="text"></span>
                    </div>
                    <label class="control-label text-align-left">课时 <span style="margin-left:30px" id="surplus"></span></label>
                </div>
            </div>
        </#if>

        <div class="col-xm-12 col-sm-6 col-lg-12" id="empAdminUserIdBox" style="display: none">
            <div class="form-group">
                <label  class="col-sm-2 col-sm-offset-1 control-label no-padding-right">所属老师：</label>
                <div class="col-sm-3">
                    <select class="form-control empAdminUserId" style="border: 1px solid #c6d5d8;border-radius: 4px !important;" name="empAdminUserId">
                        <option value="">请选择</option>
                    </select>
                </div>
                <div class="col-sm-3">
                    <span class="input-icon icon-left">
                                    <input data-bv-date-format="YYYY-MM-DD"
                                           data-bv-message="The field is not valid"
                                           data-bv-date-message="请正确输入一个时间" data-bv-date="false"
                                           name="classTime" alt="上课日期" id="birthdayDate" placeholder="上课日期"
                                           type="text" title="上课日期"
                                           class="form-control form-control date-picker classTime"
                                           onfocus="WdatePicker({doubleCalendar:true,dateFmt:'yyyy-MM-dd'})"
                                           value="${editEntity.birthdayDate}"/>
                                    <i class="fa fa-calendar"></i>
                                </span>
                </div>
                <label class="col-sm-1">
                    <a type="btn" class="btn" onclick="showLessonDialog(this)"
                       style="background-color: #23a8f5;border: none;border-radius: 4px!important;width: 120px;color: #fff;margin-right: 0!important;box-shadow:0px 0px 10px rgba(122,161,184,0.3);">
                        查询
                    </a>
                </label>
            </div>
        </div>

        <div class="col-xm-12 col-sm-6 col-lg-12" style="display: none;" id="classGradesBox">
            <div class="form-group">
                <label  class="col-sm-2 col-sm-offset-1 control-label no-padding-right">上课班级：</label>
                <input type="hidden" class="classGradesValue">
                <div class="classGrades">

                </div>

            </div>
        </div>

        <#if (true && editModel=='add')||(true && editModel=='edit')>
            <div class="col-xm-12 col-sm-6 col-lg-12">
                <div class="form-group">
                    <label  class="col-sm-2 col-sm-offset-1 control-label no-padding-right"><span style="color: red">*</span>备注：</label>
                    <div class="col-sm-8">
                        <textarea class="form-control" name="remark"  rows="3" style="resize:none" maxlength="499"
                                  id="remark" data-bv-field="remark" value="${editEntity.remark}"></textarea>
                    </div>
                </div>
            </div>
        </#if>
        <div class="col-sm-12 text-align-center margin-top-20 ">
            <button style="width: 80px;margin-right: 20px" type="submit" class="btn btn-blue"
                    id="editFormSubmitBtn_${serializeNum}">确定
            </button>
            <input style="width: 80px;" type="button" class="btn btn-blue" data-dismiss="modal" value="取消"/>

        </div>
    </form>

    <!--<span>剩余正课 ${data.surplusFormalClassHour}</span>-->
    <!--<span>剩余赠课 ${data.surplusPresentClassHour}</span>-->
    <!--<span>剩余补课 ${data.remediationClassHour}</span>-->
</div>
<script src="assets/js/validation/bootstrapValidator_init.js"></script>
<script>
    $(".selectpicker_${serializeNum}").select2();

    $("#subtractEditForm_${serializeNum}").bind("ajaxSubmitCallback", function (event, result) {
        if (result.resCode == 200) {
            bootbox.hideAll();
            logger.info("保存成功", true);
        } else {
            logger.error("保存失败");
        }
    });
    $("#classHourType").change(function () {
        var thatVal = $(this).val();
        $(this).attr("value",thatVal);
        if(thatVal){
            if (thatVal == 1) {
                $("#surplus").html("剩余"+ ${data.surplusFormalClassHour} +"课时");
                $("#classHour").attr("data-max",""+ ${data.surplusFormalClassHour} +"");
                $("#classGradesBox").hide();
                $("#empAdminUserIdBox").hide();
            } else if (thatVal == 2) {
                $("#surplus").html("剩余"+ ${data.surplusPresentClassHour} +"课时");
                $("#classHour").attr("data-max",""+ ${data.surplusPresentClassHour} +"");
                $("#classGradesBox").hide();
                $("#empAdminUserIdBox").hide();
            } else if (thatVal == 3) {
                $("#surplus").html("剩余"+ ${data.remediationClassHour} +"课时");
                $("#classHour").attr("data-max",""+ ${data.remediationClassHour} +"");
                $("#classGradesBox").show();
                $("#empAdminUserIdBox").show();
            } else {
                $("#surplus").html("");
                $("#classHour").attr("data-max","")
            }
        }
    });
    
    function verificationNumber(that) {
        var classHourType = $("#classHourType").attr("value");
        console.log(classHourType)
        if(classHourType){
            var max = $(that).attr("data-max");
            var thatVal = $(that).val();
            if(Number(thatVal) > Number(max)){
                $(that).val("");
                logger.error("课时数需要小于剩余课时数");
            }
        } else {
            $(that).val("");
            logger.error("请选择课时类型");
        }
    }

    $(function(){
        ajaxRequest("sysAdminUserController/getPostListByDuty.do",{
            duty:6
        }, function (result) {
            var data=result.data;
            var arr=['']; //<option value="0">请选择</option>
            for (var i = 0; i< data.length; i++) {
                arr.push('<option value="'+data[i].id+'">'+data[i].realName+'</option>')
            }
            $(".empAdminUserId").append(arr.join(''))
        },function(){
            ajaxError("加载员工信息失败");
        }, "post","json")
    });


    function showLessonDialog(){
        var memberPackageId=$(".memberPackageId").val();
        var empAdminUserId=$(".empAdminUserId").val();
        var classTime=$(".classTime").val();
        ajaxRequest("tssClassesLessonsController/queryByClassTimeAndAdminUserId.do",{
            empAdminUserId:empAdminUserId,
            classTime:classTime,
            memberPackageId:memberPackageId
        }, function (result) {
            var data=result.data;
            var arr=['']; //<option value="0">请选择</option>
            if(data.length > 0){
                for (var i = 0; i< data.length; i++) {
                    arr.push('<div class="col-sm-3 text-align-center">' +
                        '<a type="btn" class="col-sm-12" endTime="'+ data[i].endTime +'" startTime="'+ data[i].startTime +'" onclick="chooseClass(this)" style="background-color: #ccc;border: none;border-radius: 4px!important;height:30px;line-height:30px;color: #fff;margin-right: 0!important;box-shadow:0px 0px 10px rgba(122,161,184,0.3);cursor: pointer">' + data[i].name+
                        '</a>'+
                        '</div>')
                }
                $(".classGrades").empty().append(arr.join(''));
            } else {
                logger.error("无上课班级");
                $(".classGrades").html("");
            }
        },function(){
            ajaxError("加载课节信息失败");
        }, "get","json")
    };

    function chooseClass(that) {
        $(that).parent().parent().find("a").each(function () {
            $(this).css({
                "background-color":"#ccc"
            });
        });
        $(that).css({
            "background-color":"#23a8f5"
        });
        $(".classGradesValue").val($(that).text());
    }

</script>
